/**
 * This file is part of Wireless TransFer.
 *
 *   Wireless TransFer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *	
 *   Wireless TransFer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Wireless TransFer.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	 Copyright (C) 2011
 *   @author prebz
 */

package com.wirelesstransfer.activity.preference;

import java.util.ArrayList;
import java.util.List;

import android.widget.EditText;

public class PreferenceValues implements IPreferences{

	private List<EditText> preferenceFields;	// All TextField objects
	private List<Integer> fieldsValues;			// Values of the TextFields

	/**
	 * Constructor 
	 * @param preferenceFields all the textFields
	 */
	public PreferenceValues(List<EditText> preferenceFields){
		this.preferenceFields = preferenceFields;
		fieldsValues = new ArrayList<Integer>();
	}

	/**
	 * Set focusable and alpha on EditText Fields
	 * @return true if all the values are integers
	 */
	public boolean getValues() {
		try {
			for (EditText view : preferenceFields){
				fieldsValues.add(Integer.parseInt(view.getText().toString()));
			}
		} catch (NumberFormatException e) {
			return false;
		}
		return true;
	}

	public void setValues() {
		// TODO implement

	}

	/**
	 * Returns the value in each field
	 * @return string of all the values
	 */
	@Override
	public String toString(){
		String str = "";
		int position = 0;
		for (Integer i: fieldsValues){
			str += "Value " + position + " :" + i + "\n";
			position++;

		}
		return str;
	}
}
